﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace XDA_ROM_Hub
{
    public partial class Welcome : Form
    {
        public bool UserClosing { get; set; }

        void buttonExit_Click(object sender, EventArgs e)
        {
            UserClosing = true;
            cencelbtn();
        }

        void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            switch (e.CloseReason)
            {
                case CloseReason.ApplicationExitCall:
                    break;
                case CloseReason.FormOwnerClosing:
                    break;
                case CloseReason.MdiFormClosing:
                    break;
                case CloseReason.None:
                    break;
                case CloseReason.TaskManagerClosing:
                    break;
                case CloseReason.UserClosing:
                    if (UserClosing)
                    {
                        cencelbtn();
                    }
                    else
                    {
                        cencelbtn();
                    }
                    break;
                case CloseReason.WindowsShutDown:
                    break;
                default:
                    break;
            }
        }

        public void cencelbtn()
        {
                Properties.Settings.Default.Reset();
                if (File.Exists(Application.StartupPath + @"\build\build.prop"))
                {
                    File.Delete(Application.StartupPath + @"\build\build.prop");
                }
                Application.Exit();
            
        }

        public Welcome()
        {
            
            InitializeComponent();
            UserClosing = false;
            this.buttonExit.Click += new EventHandler(buttonExit_Click);
            this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            
            if (Properties.Settings.Default.SelectedDevice == "")
            {
                MessageBox.Show("No device is set");
            }
            else
            {
                StockRom step3_1 = new StockRom();
                step3_1.Text = Properties.Settings.Default.SelectedDevice; 
                step3_1.Show();
                //this.Hide();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            cencelbtn();
        }


        private void button4_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Please use at your own risk.\n\nThis tool is not fully tested, and I can not be held for any damage caused to your device and/or computer.", "Thank you.", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void Welcome_Load(object sender, EventArgs e)
        {
            label2.Text = "Device: " + Properties.Settings.Default.SelectedDevice;
            label1.Text = "Android Version: " + Properties.Settings.Default.AndroidVer;
        }

        private void button5_Click(object sender, EventArgs e)
        {
            Tweaks Tweaks = new Tweaks();
            Tweaks.Show();
            //this.Hide();
        }

        private void creditsbtn_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Someguyfromhell for ALL FIRMWARES\nAndroxyde for Flashtool\nDooMLorD for rooting and Unrooting\nNaA for CWM\niONEx for ROM indexing\nReaper61616 for rom downloading and hosting stuff.", "Credits", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void button6_Click(object sender, EventArgs e)
        {
            DSE dse = new DSE();
            dse.Show();
            //this.Hide();
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            About about = new About();
            about.Show();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked == true)
            {
                Properties.Settings.Default.EnableGuide = true;
            }
            else if (checkBox1.Checked == false)
            {
                Properties.Settings.Default.EnableGuide = false;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Troubleshooting proc = new Troubleshooting();
            proc.Show();

        }

        private void button7_Click(object sender, EventArgs e)
        {
            xrh_Backup proc = new xrh_Backup();
            proc.Show();
        }

        private void button8_Click(object sender, EventArgs e)
        {
            xrh_nandroid_backup p = new xrh_nandroid_backup();
            p.Show();
        }

       

    }
}
